package com.cutebaby.admin.com.processor;

import com.cutebaby.admin.com.ioc.User;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.stereotype.Component;

/**
 * @author: xialegemo
 * @description: processor
 * @date： 2020/10/23 0:40
 **/
@Component
public class TestBeanFactoryPostProcessor implements BeanFactoryPostProcessor {

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        GenericBeanDefinition bd = (GenericBeanDefinition) beanFactory.getMergedBeanDefinition("userService");

        Class<?> beanClass = bd.getBeanClass();
        // 尝试打印beanclass
        System.out.println(beanClass);

        //尝试使用processor修改BeanDefination，原始应该为userService   现在改为user
        bd.setBeanClass(User.class);
        bd.setBeanClassName("a");

    }
}
